package com.foxzzz.temporary;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Solution8 {
    public int myAtoi(String str) {
        String result = "";
        try {
            Pattern pattern = Pattern.compile("^\\s*(-|\\+){0,1}\\d+");
            Matcher matcher = pattern.matcher(str);
            while (matcher.find()) {

                result = matcher.group();
            }
            if(result.equals(""))
                return 0;
            return Integer.parseInt(result.trim());

        }catch (Exception e){
            if(str.contains("-")){
                return Integer.MIN_VALUE;
            }else
                return Integer.MAX_VALUE;
        }

    }

    public static void main(String[] args) {
       System.out.println(new Solution8().myAtoi("3.1415"));

    }
}
